<template id="select_address">
	<div class="select_address">

		<!--头部-->
		<div class="about_header">

			<div class="about_title">
				<router-link to="/about_class"><img src="../../assets/images/class/jiantou_03.png" /></router-link>

				<p>{{user.username}}</p>
				<div class="about_select">
					<div class="about_ing">
						<router-link to="/new_address"><span @click.stop="add">添加新地址</span></router-link>
					</div>
				</div>

			</div>
		</div>
		<!--头部结束-->
		<!--选择地址-->
		<div class="select_main">

			<!--个人信息-->
			<div class="select_info">
				<div class="select_most" v-for="(item,index) in fun" :key="index">
					<div class="select_new" @click.stop="delect(item.id,item)">
						<div class="select_top">
							<p>{{item.username}} {{item.phone}}</p>
							<font style="padding:1px 6px;">{{item.is_default==1 ? '使用中' : ''}}</font>
						</div>
						<div class="select_btn">
							<p>{{item.city+item.area+item.street+item.edifice+item.detail_addr}}</p>

						</div>
					</div>
					<div class="select_edit">
						<img src="../../assets/images/select_address/bianji_07.png" @click.stop="edit(item.id,item.username,item.phone,item.city,item.area,item.street,item.edifice,item.detail_addr,item.lat,item.lng)" />
					</div>
				</div>

			</div>
			<!--个人信息结束-->

			<!--继续按钮-->
			<div class="select_continue">
				<button @click.stop="keep">继续</button>
			</div>
			<!--继续按钮结束-->

		</div>
		<!--选择地址结束-->

	</div>
</template>

<script>
	export default {
		data() {
			return {
				user: '',
				fun: [],
				haha: ""
			}
		},
		computed: {
			getInfo() {
				return this.$store.state.id;
			}
		},
		created() {
			//let SESSION_ID = JSON.parse(window.sessionStorage.getItem('SESSION_ID'));
			var	 SESSION_ID=JSON.parse(window.localStorage.getItem('sessiond'))
			let obj = {
				sessionid: SESSION_ID.sessionid,
				userid: SESSION_ID.user.id,
				code: 1

			};
			let _this = this
			_this.sessionid = _this.$store.state.sessionid;
			let qs = require('qs');
			this.$axios.post("http://yogahome.top/yujia/user/findAllAddressByUser", qs.stringify(obj), {
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}

			}).then(function(response) {
				_this.user = SESSION_ID.user
				_this.fun = response.data.data
				_this.haha = response.data.data.id

			}).catch(function(error) {
				console.log(error);
			});
		},
		mounted(){
			this.select()
		},
		methods: {
			select:function(){
				 setTimeout(()=>{
					//  console.log(this.fun)
					 for(var i=0;i<this.fun.length;i++){
						//  console.log(this.fun[i].is_default)
						 if(this.fun[i].is_default == 1){
							 var addd=this.fun[i].city+this.fun[i].area+this.fun[i].street+this.fun[i].edifice+this.fun[i].detail_addr
							 window.localStorage.setItem('add', addd)
						 }
					 }
				 },1000)
				// window.localStorage.setItem('select',)
			},
			//修改地址
			edit(id, username, phone, city, area, street, edifice, detail_addr, lat, lng) {
				console.log(username)
				this.$router.push({
					path: "/edit_address",
					query: {
						id,
						username,
						phone,
						city,
						area,
						street,
						edifice,
						detail_addr,
						lat,
						lng
					}
				})
			},
			delect(id,item) {
				// console.log(item.city+item.area+item.street+item.edifice+item.detail_addr)
				var getadd=window.localStorage.setItem('add',item.city+item.area+item.street+item.edifice+item.detail_addr)
				//let SESSION_ID = JSON.parse(window.sessionStorage.getItem('SESSION_ID'));
				 var SESSION_ID=JSON.parse(window.localStorage.getItem('sessiond'))
				let obj = {
					userid: SESSION_ID.user.id,
					id: id

				};
				let _this = this
				_this.sessionid = _this.$store.state.sessionid;
				let qs = require('qs');
		_this.$axios.post("http://yogahome.top/yujia/user/setDefaultAddressByUser", qs.stringify(obj), {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}

				}).then((response) => {
					_this.user = SESSION_ID.user

					if(response.data.code == 1) {
						alert(response.data.message)
						
					}

				}).catch((error) => {
					console.log(error);
				});
				_this.$axios.post("http://yogahome.top/yujia/user/findAllAddressByUser", qs.stringify(obj), {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}

				}).then((response) => {
					_this.user = SESSION_ID.user
					_this.fun = response.data.data
				}).catch((error) => {
					console.log(error);
				});
			},
//			点击继续跳到主页
           keep(){
           	this.$router.push({
           		path:'/',
           		query:{
           			
           		}
           	})
           }

		}
	}
</script>

<style scoped>
	@import "../../assets/css/select_address.css";
</style>